package com.googlecode.chigs.web.config.configuration;

import org.apache.wicket.extensions.wizard.WizardStep;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;

import com.googlecode.chigs.domain.ConfigRevision;
import com.googlecode.chigs.domain.Product;
import com.googlecode.chigs.domain.Version;
import com.googlecode.chigs.web.doku.version.VersionLabel;
import com.googlecode.chigs.web.doku.version.VersionSelector;

public class EditOrCreateConfigurationStep extends WizardStep {
	public EditOrCreateConfigurationStep(ConfigRevision configRevision, Product product, boolean editable) {
		StringResourceModel label = new StringResourceModel("name.label", EditOrCreateConfigurationStep.this, null);
		add(new Label("name.label", label));
		add(new TextField<String>("configRevision.configuration.name")
				.setRequired(true)
				.setLabel(label)
				.setEnabled(editable));
		StringResourceModel descLabel = new StringResourceModel("description.label", EditOrCreateConfigurationStep.this, null);
		add(new Label("description.label", descLabel));
		add(new TextArea<String>("configRevision.configuration.description")
				.setRequired(true)
				.setLabel(descLabel)
				.setEnabled(editable));
		add(new Label("configRevision.nr"));

		if (configRevision.isNew()) {
			add(new VersionSelector("version", new PropertyModel<Version>(configRevision, "version"), product));
		} else {
			add(new VersionLabel("version", new Model<Version>(configRevision.getVersion())));
		}
	}
}
